unit uAddWindow;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtDlgs, StdCtrls, Mask, DBCtrlsEh, DBLookupEh, ExtCtrls;

type
  TfAddWindow = class(TForm)
    Label2: TLabel;
    GroupBox1: TGroupBox;
    Image1: TImage;
    Button1: TButton;
    DBLookupComboboxEh1: TDBLookupComboboxEh;
    Button2: TButton;
    OpenPictureDialog1: TOpenPictureDialog;
    procedure Button1Click(Sender: TObject);
    procedure Image1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  fAddWindow: TfAddWindow;

implementation

uses uDBData, uDBCommand;

{$R *.dfm}

procedure TfAddWindow.Button1Click(Sender: TObject);
var
  ImageIndex, ImageCount: Integer;
begin
  ImageCount := OpenPictureDialog1.Files.Count;
  if(ImageCount > 0) then
  begin                               
    fDBData.dWindow.DataSet.Close();
    for ImageIndex := 0 to ImageCount-1 do
    begin
      Image1.Picture.Bitmap.LoadFromFile(OpenPictureDialog1.Files.Strings[ImageIndex]);
      fDBCommand.qAddWindow.ParamByName('IDWindowGroup').Value := fDBData.dWindowGroup.DataSet.FieldByName('WindowGroupId').AsInteger;
      fDBCommand.qAddWindow.ParamByName('WindowImage').Assign(Image1.Picture.Bitmap);
      fDBCommand.qAddWindow.Execute();
    end;
    fDBData.dWindow.DataSet.Open();
  end;
  Image1.Picture.Bitmap.FreeImage();
  Button1.Enabled := False;
  Close();
end;

procedure TfAddWindow.Image1Click(Sender: TObject);
begin
  if(OpenPictureDialog1.Execute()) then
  begin
    //ShowMessage(IntToStr(OpenPictureDialog1.Files.Count));
    if(OpenPictureDialog1.Files.Count > 0) then
    begin
      Image1.Picture.Bitmap.LoadFromFile(OpenPictureDialog1.FileName);
      Button1.Enabled := True;
    end
    else Button1.Enabled := False;
  end;
end;

procedure TfAddWindow.Button2Click(Sender: TObject);
begin
  Close();
end;

end.
